package com.feature.core.domain;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class PageVo<T> {
    /**
     * 总数
     */
    protected long totalCount = 0;
    /**
     * 每页显示条数，默认 10
     */
    protected long pageSize = 10;

    /**
     * 当前页
     */
    protected long curPage = 1;

    /**
     * 总页数
     */
    private long pageCount = 0;

    /**
     * 数据
     */
    private List<T> items = new ArrayList<T>();

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getCurPage() {
        return curPage;
    }

    public void setCurPage(long curPage) {
        this.curPage = curPage;
    }

    public long getPageCount() {
        return pageCount;
    }

    public void setPageCount(long pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }

    public static <T, E> PageVo<T> of(PageVo<E> pageVo, Function<List<E>, List<T>> convert) {
        PageVo<T> vo = new PageVo<T>();
        vo.setCurPage(pageVo.getCurPage());
        vo.setPageCount(pageVo.getPageCount());
        vo.setPageSize(pageVo.getPageSize());
        vo.setTotalCount(pageVo.getTotalCount());
        vo.setItems(convert.apply(pageVo.getItems()));
        return vo;
    }
}
